<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品简称" prop="productShortName">
        <el-input
          v-model="queryParams.productShortName"
          placeholder="请输入产品简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品全称" prop="productFullName">
        <el-input
          v-model="queryParams.productFullName"
          placeholder="请输入产品全称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产单位" prop="productionUnit">
        <el-input
          v-model="queryParams.productionUnit"
          placeholder="请输入生产单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="MAH单位" prop="mahUnit">
        <el-input
          v-model="queryParams.mahUnit"
          placeholder="请输入MAH单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品线" prop="productLine">
        <el-input
          v-model="queryParams.productLine"
          placeholder="请输入产品线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="KPI类别" prop="kpiCategory">
        <el-input
          v-model="queryParams.kpiCategory"
          placeholder="请输入KPI类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="剂型" prop="dosageForm">
        <el-input
          v-model="queryParams.dosageForm"
          placeholder="请输入剂型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格" prop="specification">
        <el-input
          v-model="queryParams.specification"
          placeholder="请输入规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包装规格" prop="packagingSpec">
        <el-input
          v-model="queryParams.packagingSpec"
          placeholder="请输入包装规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保质期" prop="shelfLife">
        <el-input
          v-model="queryParams.shelfLife"
          placeholder="请输入保质期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料采购管理 (需要, 无需)" prop="materialProcurementMgmt">
        <el-input
          v-model="queryParams.materialProcurementMgmt"
          placeholder="请输入物料采购管理 (需要, 无需)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="片(粒)/瓶(盒)" prop="piecesPerBottle">
        <el-input
          v-model="queryParams.piecesPerBottle"
          placeholder="请输入片(粒)/瓶(盒)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="瓶(盒)/件(箱)" prop="bottlesPerCase">
        <el-input
          v-model="queryParams.bottlesPerCase"
          placeholder="请输入瓶(盒)/件(箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="万片(粒)/批/生产" prop="piecesPerBatch">
        <el-input
          v-model="queryParams.piecesPerBatch"
          placeholder="请输入万片(粒)/批/生产"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="理论产出(万片,万粒,万袋)" prop="theoreticalOutputPieces">
        <el-input
          v-model="queryParams.theoreticalOutputPieces"
          placeholder="请输入理论产出(万片,万粒,万袋)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="理论产出(件,箱)" prop="theoreticalOutputCases">
        <el-input
          v-model="queryParams.theoreticalOutputCases"
          placeholder="请输入理论产出(件,箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产工序(道)" prop="productionProcessCount">
        <el-input
          v-model="queryParams.productionProcessCount"
          placeholder="请输入生产工序(道)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总入库数(瓶,盒)" prop="totalInboundBottles">
        <el-input
          v-model="queryParams.totalInboundBottles"
          placeholder="请输入总入库数(瓶,盒)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总出库数(瓶,盒)" prop="totalOutboundBottles">
        <el-input
          v-model="queryParams.totalOutboundBottles"
          placeholder="请输入总出库数(瓶,盒)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总出库数(件,箱)" prop="totalOutboundCases">
        <el-input
          v-model="queryParams.totalOutboundCases"
          placeholder="请输入总出库数(件,箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现库存数(瓶,盒)" prop="currentStockBottles">
        <el-input
          v-model="queryParams.currentStockBottles"
          placeholder="请输入现库存数(瓶,盒)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现库存数(件,箱)" prop="currentStockCases">
        <el-input
          v-model="queryParams.currentStockCases"
          placeholder="请输入现库存数(件,箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安全库存(件,箱)" prop="safetyStockCases">
        <el-input
          v-model="queryParams.safetyStockCases"
          placeholder="请输入安全库存(件,箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月均计划销量(件,箱)" prop="monthlyPlannedSalesCases">
        <el-input
          v-model="queryParams.monthlyPlannedSalesCases"
          placeholder="请输入月均计划销量(件,箱)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库单位" prop="outboundUnit">
        <el-input
          v-model="queryParams.outboundUnit"
          placeholder="请输入出库单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年度指标" prop="annualTarget">
        <el-input
          v-model="queryParams.annualTarget"
          placeholder="请输入年度指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年度销售" prop="annualSales">
        <el-input
          v-model="queryParams.annualSales"
          placeholder="请输入年度销售"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指标完成率" prop="targetCompletionRate">
        <el-input
          v-model="queryParams.targetCompletionRate"
          placeholder="请输入指标完成率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属中心" prop="center">
        <el-input
          v-model="queryParams.center"
          placeholder="请输入所属中心"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一级部门" prop="departmentLevel1">
        <el-input
          v-model="queryParams.departmentLevel1"
          placeholder="请输入一级部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务部门" prop="departmentLevel3">
        <el-input
          v-model="queryParams.departmentLevel3"
          placeholder="请输入业务部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdOn">
        <el-date-picker clearable
          v-model="queryParams.createdOn"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedOn">
        <el-date-picker clearable
          v-model="queryParams.updatedOn"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hbs:productArchive:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hbs:productArchive:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hbs:productArchive:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hbs:productArchive:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productArchiveList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="销售状态 (在售, 停售)" align="center" prop="salesStatus" />
      <el-table-column label="产品简称" align="center" prop="productShortName" />
      <el-table-column label="产品全称" align="center" prop="productFullName" />
      <el-table-column label="生产单位" align="center" prop="productionUnit" />
      <el-table-column label="MAH单位" align="center" prop="mahUnit" />
      <el-table-column label="物料编码" align="center" prop="materialCode" />
      <el-table-column label="产品线" align="center" prop="productLine" />
      <el-table-column label="KPI类别" align="center" prop="kpiCategory" />
      <el-table-column label="剂型" align="center" prop="dosageForm" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="规格" align="center" prop="specification" />
      <el-table-column label="包装规格" align="center" prop="packagingSpec" />
      <el-table-column label="保质期" align="center" prop="shelfLife" />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column label="物料采购管理 (需要, 无需)" align="center" prop="materialProcurementMgmt" />
      <el-table-column label="片(粒)/瓶(盒)" align="center" prop="piecesPerBottle" />
      <el-table-column label="瓶(盒)/件(箱)" align="center" prop="bottlesPerCase" />
      <el-table-column label="万片(粒)/批/生产" align="center" prop="piecesPerBatch" />
      <el-table-column label="理论产出(万片,万粒,万袋)" align="center" prop="theoreticalOutputPieces" />
      <el-table-column label="理论产出(件,箱)" align="center" prop="theoreticalOutputCases" />
      <el-table-column label="生产工序(道)" align="center" prop="productionProcessCount" />
      <el-table-column label="总入库数(瓶,盒)" align="center" prop="totalInboundBottles" />
      <el-table-column label="总出库数(瓶,盒)" align="center" prop="totalOutboundBottles" />
      <el-table-column label="总出库数(件,箱)" align="center" prop="totalOutboundCases" />
      <el-table-column label="现库存数(瓶,盒)" align="center" prop="currentStockBottles" />
      <el-table-column label="现库存数(件,箱)" align="center" prop="currentStockCases" />
      <el-table-column label="安全库存(件,箱)" align="center" prop="safetyStockCases" />
      <el-table-column label="月均计划销量(件,箱)" align="center" prop="monthlyPlannedSalesCases" />
      <el-table-column label="出库单位" align="center" prop="outboundUnit" />
      <el-table-column label="年度指标" align="center" prop="annualTarget" />
      <el-table-column label="年度销售" align="center" prop="annualSales" />
      <el-table-column label="指标完成率" align="center" prop="targetCompletionRate" />
      <el-table-column label="所属中心" align="center" prop="center" />
      <el-table-column label="一级部门" align="center" prop="departmentLevel1" />
      <el-table-column label="业务部门" align="center" prop="departmentLevel3" />
      <el-table-column label="创建时间" align="center" prop="createdOn" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdOn, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedOn" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedOn, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hbs:productArchive:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hbs:productArchive:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品档案主档对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品简称" prop="productShortName">
          <el-input v-model="form.productShortName" placeholder="请输入产品简称" />
        </el-form-item>
        <el-form-item label="产品全称" prop="productFullName">
          <el-input v-model="form.productFullName" placeholder="请输入产品全称" />
        </el-form-item>
        <el-form-item label="生产单位" prop="productionUnit">
          <el-input v-model="form.productionUnit" placeholder="请输入生产单位" />
        </el-form-item>
        <el-form-item label="MAH单位" prop="mahUnit">
          <el-input v-model="form.mahUnit" placeholder="请输入MAH单位" />
        </el-form-item>
        <el-form-item label="物料编码" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="产品线" prop="productLine">
          <el-input v-model="form.productLine" placeholder="请输入产品线" />
        </el-form-item>
        <el-form-item label="KPI类别" prop="kpiCategory">
          <el-input v-model="form.kpiCategory" placeholder="请输入KPI类别" />
        </el-form-item>
        <el-form-item label="剂型" prop="dosageForm">
          <el-input v-model="form.dosageForm" placeholder="请输入剂型" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="包装规格" prop="packagingSpec">
          <el-input v-model="form.packagingSpec" placeholder="请输入包装规格" />
        </el-form-item>
        <el-form-item label="保质期" prop="shelfLife">
          <el-input v-model="form.shelfLife" placeholder="请输入保质期" />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="物料采购管理 (需要, 无需)" prop="materialProcurementMgmt">
          <el-input v-model="form.materialProcurementMgmt" placeholder="请输入物料采购管理 (需要, 无需)" />
        </el-form-item>
        <el-form-item label="片(粒)/瓶(盒)" prop="piecesPerBottle">
          <el-input v-model="form.piecesPerBottle" placeholder="请输入片(粒)/瓶(盒)" />
        </el-form-item>
        <el-form-item label="瓶(盒)/件(箱)" prop="bottlesPerCase">
          <el-input v-model="form.bottlesPerCase" placeholder="请输入瓶(盒)/件(箱)" />
        </el-form-item>
        <el-form-item label="万片(粒)/批/生产" prop="piecesPerBatch">
          <el-input v-model="form.piecesPerBatch" placeholder="请输入万片(粒)/批/生产" />
        </el-form-item>
        <el-form-item label="理论产出(万片,万粒,万袋)" prop="theoreticalOutputPieces">
          <el-input v-model="form.theoreticalOutputPieces" placeholder="请输入理论产出(万片,万粒,万袋)" />
        </el-form-item>
        <el-form-item label="理论产出(件,箱)" prop="theoreticalOutputCases">
          <el-input v-model="form.theoreticalOutputCases" placeholder="请输入理论产出(件,箱)" />
        </el-form-item>
        <el-form-item label="生产工序(道)" prop="productionProcessCount">
          <el-input v-model="form.productionProcessCount" placeholder="请输入生产工序(道)" />
        </el-form-item>
        <el-form-item label="总入库数(瓶,盒)" prop="totalInboundBottles">
          <el-input v-model="form.totalInboundBottles" placeholder="请输入总入库数(瓶,盒)" />
        </el-form-item>
        <el-form-item label="总出库数(瓶,盒)" prop="totalOutboundBottles">
          <el-input v-model="form.totalOutboundBottles" placeholder="请输入总出库数(瓶,盒)" />
        </el-form-item>
        <el-form-item label="总出库数(件,箱)" prop="totalOutboundCases">
          <el-input v-model="form.totalOutboundCases" placeholder="请输入总出库数(件,箱)" />
        </el-form-item>
        <el-form-item label="现库存数(瓶,盒)" prop="currentStockBottles">
          <el-input v-model="form.currentStockBottles" placeholder="请输入现库存数(瓶,盒)" />
        </el-form-item>
        <el-form-item label="现库存数(件,箱)" prop="currentStockCases">
          <el-input v-model="form.currentStockCases" placeholder="请输入现库存数(件,箱)" />
        </el-form-item>
        <el-form-item label="安全库存(件,箱)" prop="safetyStockCases">
          <el-input v-model="form.safetyStockCases" placeholder="请输入安全库存(件,箱)" />
        </el-form-item>
        <el-form-item label="月均计划销量(件,箱)" prop="monthlyPlannedSalesCases">
          <el-input v-model="form.monthlyPlannedSalesCases" placeholder="请输入月均计划销量(件,箱)" />
        </el-form-item>
        <el-form-item label="出库单位" prop="outboundUnit">
          <el-input v-model="form.outboundUnit" placeholder="请输入出库单位" />
        </el-form-item>
        <el-form-item label="年度指标" prop="annualTarget">
          <el-input v-model="form.annualTarget" placeholder="请输入年度指标" />
        </el-form-item>
        <el-form-item label="年度销售" prop="annualSales">
          <el-input v-model="form.annualSales" placeholder="请输入年度销售" />
        </el-form-item>
        <el-form-item label="指标完成率" prop="targetCompletionRate">
          <el-input v-model="form.targetCompletionRate" placeholder="请输入指标完成率" />
        </el-form-item>
        <el-form-item label="所属中心" prop="center">
          <el-input v-model="form.center" placeholder="请输入所属中心" />
        </el-form-item>
        <el-form-item label="一级部门" prop="departmentLevel1">
          <el-input v-model="form.departmentLevel1" placeholder="请输入一级部门" />
        </el-form-item>
        <el-form-item label="业务部门" prop="departmentLevel3">
          <el-input v-model="form.departmentLevel3" placeholder="请输入业务部门" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdOn">
          <el-date-picker clearable
            v-model="form.createdOn"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedOn">
          <el-date-picker clearable
            v-model="form.updatedOn"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProductArchive, getProductArchive, delProductArchive, addProductArchive, updateProductArchive } from "@/api/hbs/productArchive"

export default {
  name: "ProductArchive",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品档案主档表格数据
      productArchiveList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        salesStatus: null,
        productShortName: null,
        productFullName: null,
        productionUnit: null,
        mahUnit: null,
        materialCode: null,
        productLine: null,
        kpiCategory: null,
        dosageForm: null,
        productName: null,
        specification: null,
        packagingSpec: null,
        shelfLife: null,
        brand: null,
        materialProcurementMgmt: null,
        piecesPerBottle: null,
        bottlesPerCase: null,
        piecesPerBatch: null,
        theoreticalOutputPieces: null,
        theoreticalOutputCases: null,
        productionProcessCount: null,
        totalInboundBottles: null,
        totalOutboundBottles: null,
        totalOutboundCases: null,
        currentStockBottles: null,
        currentStockCases: null,
        safetyStockCases: null,
        monthlyPlannedSalesCases: null,
        outboundUnit: null,
        annualTarget: null,
        annualSales: null,
        targetCompletionRate: null,
        center: null,
        departmentLevel1: null,
        departmentLevel3: null,
        createdOn: null,
        updatedOn: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询产品档案主档列表 */
    getList() {
      this.loading = true
      listProductArchive(this.queryParams).then(response => {
        this.productArchiveList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        salesStatus: null,
        productShortName: null,
        productFullName: null,
        productionUnit: null,
        mahUnit: null,
        materialCode: null,
        productLine: null,
        kpiCategory: null,
        dosageForm: null,
        productName: null,
        specification: null,
        packagingSpec: null,
        shelfLife: null,
        brand: null,
        materialProcurementMgmt: null,
        piecesPerBottle: null,
        bottlesPerCase: null,
        piecesPerBatch: null,
        theoreticalOutputPieces: null,
        theoreticalOutputCases: null,
        productionProcessCount: null,
        totalInboundBottles: null,
        totalOutboundBottles: null,
        totalOutboundCases: null,
        currentStockBottles: null,
        currentStockCases: null,
        safetyStockCases: null,
        monthlyPlannedSalesCases: null,
        outboundUnit: null,
        annualTarget: null,
        annualSales: null,
        targetCompletionRate: null,
        center: null,
        departmentLevel1: null,
        departmentLevel3: null,
        createdOn: null,
        updatedOn: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加产品档案主档"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getProductArchive(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改产品档案主档"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProductArchive(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addProductArchive(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除产品档案主档编号为"' + ids + '"的数据项？').then(function() {
        return delProductArchive(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hbs/productArchive/export', {
        ...this.queryParams
      }, `productArchive_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
